﻿
$(function () {

    //加载所有的带接入列表
    $.ajax({
        type: "POST",
        url: "../api/SocketApi/GetAllCustomerWaitGet",
        dataType: "json",
        success: function (data) {
            if (data.Result) {
                if (data.Data.length <= 0) {
                    return;
                }
                var _html = CreateCustomerWaitList(data.Data);
                $(".waitInList .waitInListUL").append(_html);
                stasticWaitCount();
            }
            else {
                alert("初始化数据失败");
            }
        }
    });
    //GetBeforeUserList("");

    setTimeout(function () {
        //获取当前在线客服人数
        $.ajax({
            type: "POST",
            url: "../api/SocketApi/GetCurrentOnlineServiceCount",
            dataType: "json",
            success: function (data) {
                if (data.Result) {
                    $(".serviceOnlineCount").html(data.Data || 1);
                }
                else {
                    alert("获取当前在线客服人数失败");
                }
            }
        });
    }, 2000)

    //==============================特效start==========================
    //回车事件
    document.onkeydown = function (event) {
        var e = event || window.event;
        if (e && e.keyCode == 13) { //回车键的键值为13
            $(".chatWindowsList .chat:visible").find(".chatSend").click();
        }
    };
    $(document).on("mouseover", ".chatTargetList ul li", function () {
        $(this).children("i").show();
    })
    $(document).on("mouseleave", ".chatTargetList ul li", function () {
        $(this).children("i").hide();
    })
    //点击聊天区域左边的用户列表
    $(document).on("click", ".chatTargetList ul li", function () {
        $(this).addClass("liSelected").siblings().removeClass("liSelected");
        var _index = $(this).index();
        if (_index < 0)
            return;
        var _cjar = $(".chat")
        _cjar.eq(_index).show().siblings(".chat").hide();
        $(this).find(".messageCount").html("0").hide();
    })

    $(document).on("mouseover", ".waitInList ul li", function () {
        $(this).children("i").show();
    })
    $(document).on("mouseleave", ".waitInList ul li", function () {
        $(this).children("i").hide();
    })
    $("#imgCancelBtn").on("click", function () {
        $("#sendImageDiv").hide();
        $("#fileImageImg").attr("src", "");
    })
    //==============================特效end=========================

    //查询最近通话用户按钮    
    $("#searchBtn").on("click", function () {
        var _name = $.trim($("#searchName").val());
        $(".beforeInListUL").html("");
        GetBeforeUserList(_name);
    })

    //隐藏聊天记录框
    $(".opera").on("click", function () {
        $(".chatRecord").hide(300);
    })

    //清除未读消息
    $("#chatWindows").on("click", function () {
        $(".chatTargetList ul .liSelected").find(".messageCount").html("0").hide();

    })

    //查看客户之前的聊天记录
    $(document).on("click", ".messageRecord", function () {
        var openid = $(this).parents(".chat").attr("openId");
        var name = $(this).parents(".chat").find(".name").html();
        $(".recordTitleName").html(name);
        var _data = { OpenId: openid, TimeRange: 100, sEcho: 1, iDisplayLength: 500, iDisplayStart: 0 };
        $.ajax({
            url: "/SocketChat/GetChatRecord",
            dataType: "json",
            type: "GET",
            data: _data,
            success: function (data) {

                var _ele = $(".recordContent ul");
                _ele.html("");
                data.aaData.forEach(function (item, index, array) {
                    var _html = "";
                    var _name = (item.RealName == "null" || !item.RealName) ? item.NickName : item.RealName
                    //100:客户消息
                    if (item.MessageSource == 100) {
                        _html += buildCustomerMessage(item.Message, item.MessageType, item.CreateTime, _name, item.HeadLogo);
                    }//200：客服消息
                    else if (item.MessageSource == 200) {
                        _html += buildServiceMessage(item.Message, item.MessageType, item.CreateTime, item.UserDisPlayName);
                    }
                    _ele.append(_html);
                })
            }
        });
        $(".chatRecord").show(500);
    })

    //查看大图
    $(document).on("click", ".mineMessageText img", function () {
        var _src = $(this).attr("src");
        lookBigImg(_src);
    })

    $(".imageContent").on("dblclick", function () {
        $(".imageDetial,.imageContent").hide();
    })
    $(".imageDetial").on("click", function () {
        $(".imageDetial,.imageContent").hide();
    })

    //待接入和历史记录切换
    $(".waitInTitle .titleTap span").on("click", function () {
        if ($(this).index() == 0) {
            $(".searchContent").hide();
        } else if (!$(this).hasClass("currentTap")) {
            $(".searchContent").show();
            //重新载入最近通话
            $("#searchBtn").click();
        }
        $(this).addClass("currentTap").siblings().removeClass("currentTap");
        $(".waitInList ul").eq($(this).index()).show().siblings("ul").hide();
    })

    //关闭单个通话
    $(document).on("click", ".chatTargetList ul li i", function () {
        if (confirm("确定要关闭当前通话吗？")) {
            var _li = $(this).parent("li");
            var _hasClass = _li.hasClass("liSelected");
            var _prev = _li.prev();
            var _next = _li.next();
            var _openId = _li.attr("openId");

            var isSendMessage = $(".chatWindowsList .chat[openId='" + _openId + "'] .chatContent ul li").length > 0;
            closeCustomerConn(_openId, isSendMessage, function () {
                //关闭连接通道
                _li.remove();
                $(".chatWindowsList .chat[openId='" + _openId + "']").remove();
                if (_hasClass) {
                    if (_prev) {
                        _prev.trigger("click");
                    } else if (_next) {
                        _next.trigger("click");
                    }
                }
                //没有会话人数的时候隐藏通话框
                if ($(".chatTargetList ul li").length <= 0) {
                    $("#chatWindows").hide();
                }
            });

        }
    })

    //关闭单个通话
    $(document).on("click", ".chatClose", function () {
        if (confirm("确定要关闭当前通话吗？")) {
            var _this = $(this);
            var _openId = _this.parents(".chat").attr("openId");
            var _li = $(".chatTargetList ul li[openId='" + _openId + "']");
            var _prev = _li.prev();
            var _next = _li.next();
            var isSendMessage = _this.parents(".chat").find(".chatContent ul li").length > 0;
            closeCustomerConn(_openId, isSendMessage, function () {
                //关闭连接通道
                _this.parents(".chat").remove();
                $(".chatTargetList ul li[openId='" + _openId + "']").remove();

                if (_prev) {
                    _prev.trigger("click");
                } else if (_next) {
                    _next.trigger("click");
                }
                //没有会话人数的时候隐藏通话框
                if ($(".chatTargetList ul li").length <= 0) {
                    $("#chatWindows").hide();
                }
            });

        }
    })

    //接入客户
    $(document).on("dblclick", ".waitInList .beforeInListUL li", function () {
        var _this = $(this);
        var _openId = _this.attr("openId"); //微信OpenId
        var _data = _this.attr("userinfo");
        //加载当前客户信息
        $.ajax({
            type: "GET",
            url: "../api/SocketApi/CurrentCustomerState",
            data: { openId: _openId, userId: userId },
            dataType: "json",
            success: function (data) {
                if (!data.Result) {
                    alert(data.Message);
                    return;
                }
                //生成数据
                if (_data) {
                    _data = JSON.parse(_data);
                    var _rightContent = buildGetInHtml(_data, _this);
                }
            }
        });
    })

    //接入客户
    $(document).on("dblclick", ".waitInList .waitInListUL li", function () {
        var _this = $(this);
        var _openId = _this.attr("openId"); //微信OpenId
        $.ajax({
            type: "GET",
            url: "../api/SocketApi/CustomerServiceGet",
            data: { openId: _openId, userId: userId },
            dataType: "json",
            success: function (data) {
                if (!data.Result) {
                    alert(data.Message);
                    return;
                }
                //生成数据
                var _rightContent = buildGetInHtml(data.Data, _this);
                _this.remove();
                stasticWaitCount();
            }
        });
    })

    //发送消息
    $(document).on("click", ".chatSend", function () {
        var _this = $(this);
        var content = _this.parents(".chatFloorOperation").find("textarea").val();
        var openId = _this.parents(".chat").attr("openid");
        if (!content || !$.trim(content)) {
            alert("发送内容不能为空！");
            return;
        }
        if (!openId || !$.trim(openId)) {
            alert("客户信息错误！");
            return;
        }
        var time = moment(new Date()).format('YYYY-MM-DD HH:mm');
        var name = userName;
        sendMessage(openId, time, content, 100, function () {
            //本地数据
            var _html = buildServiceMessage(content, 100, time, name)
            _this.parents(".chat").children(".chatContent").children("ul").append(_html);
            _this.parents(".chatFloorOperation").find("textarea").val("");
            //自动滑倒滚动条最下面
            var _div = _this.parents(".chat").children(".chatContent");
            var jsdiv = _div[0];
            jsdiv.scrollTop = jsdiv.scrollHeight;
        })
    })

    //选择图片消息
    $(document).on("click", ".toolOperation .tools .imgChoose", function () {
        $("#fileImageInput").click();
    })
    //发送图片消息
    $(document).on("click", "#imgSendBtn", function () {
        //获取base64图片
        var imgBase64 = $("#fileImageImg").attr("src");
        //获取接收方的OpenId，当前显示的用户
        var targetUser = $(".chatWindowsList .chat:visible");
        var openId = targetUser.attr("openId");
        var time = moment(new Date()).format('YYYY-MM-DD HH:mm');
        sendMessage(openId, time, imgBase64, 200, function () {
            //本地数据
            var _html = buildServiceMessage(imgBase64, 200, time, userName)
            targetUser.children(".chatContent").children("ul").append(_html);
            //自动滑倒滚动条最下面
            var _div = targetUser.children(".chatContent");
            var jsdiv = _div[0];
            jsdiv.scrollTop = jsdiv.scrollHeight;
            $("#sendImageDiv").hide();
        });

    })

    //弹出添加备注框
    $(document).on("click", ".toolOperation .tools .imgAddRemark", function () {
        var _openId = $(this).parents(".chat").attr("openId");
        if (!_openId) {
            alert("未获取到用户信息");
            return;
        }
        $("#addRemarkDiv").show();
        $("#CurrentOpenId").val(_openId);
        $("#realName").val("");
        $("#userRemark").val("");
        $("#phone").val("");
        //获取用户之前的用户备注
        $.ajax({
            url: "/SocketChat/GetUserRemark",
            dataType: "json",
            type: "GET",
            data: { openId: _openId },
            success: function (data) {
                if (data.Result) {
                    $("#realName").val(data.Data.RealName);
                    $("#userRemark").val(data.Data.Remark);
                    $("#phone").val(data.Data.Phone);
                }
            }
        });
    })
    $("#cancelRemarkBtn").on("click", function () {
        $("#addRemarkDiv").hide();
    })
    //添加备注表单提交
    $("#addRemarkBtn").on("click", function () {
        $(this).attr('disabled', "true");
        var _data = {};
        _data.OpenId = $.trim($("#CurrentOpenId").val());
        _data.RealName = $.trim($("#realName").val());
        _data.Phone = $.trim($("#phone").val());
        _data.Remark = $.trim($("#userRemark").val());
        if (!_data.RealName && !_data.Remark && !_data.Phone) {
            alert("至少要填写一项才能提交哦");
            $(this).removeAttr('disabled');
            return;
        }

        $.ajax({
            url: "/SocketChat/AddUserRemark",
            dataType: "json",
            type: "GET",
            data: _data,
            success: function (data) {
                $("#addWarrantyRecordNoBtn").removeAttr('disabled');
                alert(data.Message);
                if (data.Result) {
                    $("#addRemarkDiv").hide();
                    if (_data.RealName) {
                        $(".chatTargetList ul li[openId='" + _data.OpenId + "']").find(".realName").html(_data.RealName);
                        $(".chat[openId='" + _data.OpenId + "']").find(".name").html(_data.RealName);
                        //$(".recordContent ul .targetMessage").find(".name").html(_data.RealName);
                    }
                    if (_data.Remark) {
                        $(".chat [openId='" + _data.OpenId + "']").find(".remark").html(_data.Remark);
                    }
                }
            }
        });
    })

    //弹框——关联报案单号
    $(document).on("click", ".imgAssociatedWarrantyRecordNo", function () {
        var _openId = $(this).parents(".chat").attr("openId");
        if (!_openId) {
            alert("未获取到用户信息");
            return;
        }
        $("#CurrentOpenId").val(_openId);
        $("#associatedWarrantyRecordNo").show();
        $("#WarrantyRecordNo").val("");
        $("#areaHasOrder").html("");
        $.ajax({
            url: "/SocketChat/GetUserOrderList",
            dataType: "json",
            type: "GET",
            data: { openId: _openId },
            success: function (data) {
                if (data.Result) {
                    var orderList = "";
                    data.Data.forEach(function (item) {
                        orderList += item.WarrantyRecordNo + "\r\n"
                    })
                    $("#areaHasOrder").html(orderList);
                }
            }
        });
    })
    //关闭弹框——关联报案单号
    $("#cancelWarrantyRecordNoBtn").on("click", function () {
        $("#associatedWarrantyRecordNo").hide();
        $("#WarrantyRecordNo").val("");
    })
    //提交数据--关联报案单号
    $("#addWarrantyRecordNoBtn").on("click", function () {
        $(this).attr('disabled', "true");
        var _data = {};
        _data.OpenId = $.trim($("#CurrentOpenId").val());
        _data.WarrantyRecordNo = $.trim($("#WarrantyRecordNo").val());
        if (!_data.OpenId || !_data.WarrantyRecordNo) {
            alert("请填写报案单号！");
            $(this).removeAttr('disabled');
            return;
        }
        $.ajax({
            url: "/SocketChat/AssociatedWarrantyRecordNo",
            dataType: "json",
            type: "GET",
            data: _data,
            success: function (data) {
                $("#addWarrantyRecordNoBtn").removeAttr('disabled');
                alert(data.Message);
                if (data.Result) {
                    $("#associatedWarrantyRecordNo").hide();
                }
            }
        });
    })

    //拖拽功能
    var oBox = document.getElementById("chatWindows");
    var oBar = document.getElementById("moveLayer");
    startDrag(oBar, oBox);
})

//发送消息 content:文本或者base64图片 messageType:文本100图片200
function sendMessage(openId, time, content, messageType, callBack) {
    var _data = {};
    _data.OpenId = openId;
    _data.Time = time;
    _data.Message = content;
    _data.MessageType = messageType;
    //发送到客户
    $.ajax({
        url: "/SocketChat/SendMessageToCustomer",
        dataType: "json",
        type: "POST",
        data: _data,
        success: function (data) {
            if (data.Result)
                callBack();
            else
                alert(data.Message);
        }
    });
}

//统计待接入总人数
function stasticWaitCount() {
    var count = $(".waitInList .waitInListUL li").length;
    $("#waitInMove .currentTap font").text(count);
}

//从待接入列表中移除某个客户
function RemoveCustomerFromWaitList(openId) {
    $(".waitInList .waitInListUL li[openid='" + openId + "']").remove();
    stasticWaitCount();
}
//生成客户待接入列表
function CreateCustomerWaitList(data) {
    var _html = "";
    for (var i = 0, j = data.length; i < j; i++) {
        var item = data[i];
        _html += ' <li openId="' + item.OpenId + '" userInfo=\'' + JSON.stringify(item) + '\'  title="' + item.NickName + '">';
        _html += '  <img src="' + item.HeadLogo + '">';
        _html += ' <span class="realName">' + (item.RealName == "null" || !item.RealName ? item.NickName : item.RealName) + '</span>';
        // _html += ' <i style="display: none;">⊗</i>';
        _html += ' </li>';
    }
    return _html;
}

//图片改变事件
function selectImageChange(obj) {
    var file = obj.files[0];
    var type = file.name.substr(file.name.lastIndexOf(".") + 1).toLocaleLowerCase();
    switch (type) {
        case "jpg":
        case "gif":
        case "png":
        case "jpeg":
        case "bmp":
            $("#sendImageDiv").show();
            var ready = new FileReader();
            ready.readAsDataURL(file);
            ready.onload = function () {
                var url = this.result;
                dealImage(url, { width: 0, height: 0, quality: 0.7 }, function (obj) {
                    $("#fileImageImg").attr("src", obj);
                });
            }
            break;
        default:
            alert("请使用图片格式的文件！");
            break;
    }
}

//* 图片压缩，默认同比例压缩
//* param {Object} path
//*   pc端传入的路径可以为相对路径，但是在移动端上必须传入的路径是照相图片储存的绝对路径
//* param {Object} obj
//*   obj 对象 有 width， height， quality(0-1)
//* param {Object} callback
//*   回调函数有一个参数，base64的字符串数据
function dealImage(path, obj, callback) {
    var img = new Image();
    img.src = path;
    img.onload = function () {
        var that = this;
        // 默认按比例压缩
        var w = that.width,
         h = that.height,
         scale = w / h;
        w = obj.width || w;
        h = obj.height || (w / scale);
        var quality = 0.7;  // 默认图片质量为0.7
        //生成canvas
        var canvas = document.createElement('canvas');
        var ctx = canvas.getContext('2d');
        // 创建属性节点
        var anw = document.createAttribute("width");
        anw.nodeValue = w;
        var anh = document.createAttribute("height");
        anh.nodeValue = h;
        canvas.setAttributeNode(anw);
        canvas.setAttributeNode(anh);
        ctx.drawImage(that, 0, 0, w, h);
        // 图像质量
        if (obj.quality && obj.quality <= 1 && obj.quality > 0) {
            quality = obj.quality;
        }
        // quality值越小，所绘制出的图像越模糊
        var base64 = canvas.toDataURL('image/jpeg', quality);
        // 回调函数返回base64的值
        callback(base64);
    }
}

//查看大图
function lookBigImg(_src) {
    if (!_src)
        return;
    window.open(_src)
    //var newImg = new Image();
    //newImg.src = _src;
    //var rw = newImg.width;
    //var rh = newImg.height;
    //$(".imageContent img").attr("src", _src);
    ////if (rh > $(".imageDetial").height()) {
    ////    $(".imageContent img").css("max-height", $(".imageDetial").height());
    ////    rh = $(".imageDetial").height();
    ////}
    ////if (rw > $(".imageDetial").width()) {
    ////    $(".imageContent img").css("max-width", $(".imageDetial").width());
    ////    rw = $(".imageDetial").width();
    ////}
    ////$(".imageContent").attr("style", "margin-top:-" + parseInt(rh / 2) + "px;margin-left:-" + parseInt(rw / 2) + "px;").show();
    //$(".imageContent").show();
    //$(".imageDetial").show();
}
//图片右转
var currentRight = 0;
function btnRight90(_this) {
    event.stopPropagation();
    currentRight = (currentRight + 90) % 360;
    $(_this).parent().css("transform", 'rotate(' + currentRight + 'deg)');

}

//拼接客户消息
function buildCustomerMessage(Message, MessageType, Time, nickName, logo) {
    debugger;
    var messageContent = "";
    var message = Message;
    if (MessageType == 200) {
        message = "<img src='" + Message + "' style='width:100%;border-radius:none;' >";
    } else if (MessageType == 300) {
        message = '<audio src="' + Message + '" controls preload="none"></audio>';
    }

    messageContent += '    <li class="targetMessage">';
    messageContent += '       <div>';
    messageContent += '             <img src="' + logo + '" title="头像" />';
    messageContent += '         </div>';
    messageContent += '          <div style="margin-left:15px;">';
    messageContent += '            <span class="name">' + nickName + '</span>';
    messageContent += '             <span>' + moment(Time).format('YYYY-MM-DD HH:mm') + '</span>';
    messageContent += '              <div class="mineMessageDiv">';
    messageContent += '                   <div class="sanjiao"></div>';
    messageContent += '                   <div class="mineMessageText">';
    messageContent += message;
    messageContent += '                   </div>';
    messageContent += '                </div>';
    messageContent += '            </div>';
    messageContent += '      </li>';
    return messageContent;
}
//拼接客服消息
function buildServiceMessage(Message, MessageType, Time, nickName) {
    var message = Message;
    if (MessageType == 200) {
        message = "<img src='" + Message + "' style='width:100%;border-radius:none;' >";
    }
    var _html = '<li class="mineMessage">';
    _html += '   <div>';
    _html += '            <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" title="头像" />';
    _html += '        </div>';
    _html += '       <div style="margin-right:15px;">';
    _html += '           <span>' + moment(Time).format('YYYY-MM-DD HH:mm') + '</span>';
    _html += '            <span>' + nickName + '</span>';
    _html += '           <div class="mineMessageDiv">';
    _html += '                <div class="sanjiao"></div>';
    _html += '                <div class="mineMessageText">';
    _html += message;
    _html += '               </div>';
    _html += '            </div>';
    _html += '        </div>';
    _html += '   </li>';
    return _html;
}

//关闭用户通道 isSendMessage:是否发送通知消息 
function closeCustomerConn(openId, isSendMessage, callBack) {
    $.ajax({
        url: "../api/SocketApi/CustomerCloseConn",
        dataType: "json",
        type: "GET",
        data: { openId: openId, isSendMessage: isSendMessage },
        success: function (data) {
            if (!data.Result) {
                alert(data.Message);
            }
            else
                callBack();
        }
    });
}

//获取最近通话列表
function GetBeforeUserList(_name) {
    //加载最近通话列表
    $.ajax({
        type: "POST",
        url: "/SocketChat/GetBeforeChatUser",
        dataType: "json",
        data: {
            name: _name
        },
        success: function (data) {
            if (data.Result) {
                if (data.Data.length <= 0) {
                    return;
                }
                var _html = CreateCustomerWaitList(data.Data);
                $(".waitInList .beforeInListUL").append(_html);
            }
            else {
                alert("初始化数据失败");
            }
        }
    });

}


//拼接接入消息
function buildGetInHtml(_data, _this) {
    var _openId = _data.OpenId;
    //头像
    var logo = _data.HeadLogo;
    //真实姓名
    var realName = _data.RealName == "null" || !_data.RealName ? _data.NickName : _data.RealName;
    //昵称
    var nickName = _data.NickName;
    //备注
    var remark = _data.Remark == "null" || !_data.Remark ? "" : _data.Remark;

    //------------------------------------添加左边的用户列表
    var _leftUserLiet = '<li openId="' + _openId + '" title="' + nickName + '" >';
    _leftUserLiet += _this.html();
    _leftUserLiet += '</li>';
    var _newElement = $(_leftUserLiet);
    _newElement.append("<i style=\"display: none;\">⊗</i>");
    _newElement.append("<font class='messageCount' style='display:none'>0</font>");
    $(".chatTargetList ul").append(_newElement);

    //---------------------------------------添加右边的聊天框
    var _rightContent = '<div class="chat" style="display:none;" openId="' + _openId + '">';
    _rightContent += '<div class="targetLogo">';
    _rightContent += '<div class="imgContent">';
    _rightContent += '<img src="' + logo + '" title="头像" />';
    _rightContent += '</div>';
    _rightContent += ' <div class="userTitle"><div class="name">' + realName + '</div><div class="remark" title="' + remark + '">' + remark + '</div></div>';
    _rightContent += '</div>';
    _rightContent += '<div class="chatContent" style="display:block;">';
    _rightContent += ' <ul>';

    //---------消息体Start
    var messageContent = "";
    if (_data.CustomerPoolModel) {
        _data.CustomerPoolModel.forEach(function (item, index, array) {
            messageContent += buildCustomerMessage(item.Message, item.MessageType, item.Time, realName, logo);
        });
    }

    _rightContent += messageContent;
    //---------消息体End

    _rightContent += '    </ul>';
    _rightContent += ' </div>';
    _rightContent += ' <div class="chatFloorOperation">';
    _rightContent += '    <div class="toolOperation">';
    _rightContent += '       <span class="tools">';
    _rightContent += '         <img src="../../Images/1182678.gif" class="imgChoose" title="图片" />';
    _rightContent += '       </span>';
    _rightContent += '       <span class="tools">';
    _rightContent += '         <img src="../../Images/remark.png" class="imgAddRemark" style="height:18px;" title="备注" />';
    _rightContent += '       </span>';
    _rightContent += '       <span class="tools">';
    _rightContent += '         <img src="../../Images/remark.png" class="imgAssociatedWarrantyRecordNo" style="height:18px;" title="关联报案单" />';
    _rightContent += '       </span>';
    _rightContent += '      <span class="messageRecord">聊天记录</span>';
    _rightContent += ' </div>';
    _rightContent += '   <div class="contentArea">';
    _rightContent += '      <textarea></textarea>';
    _rightContent += '  </div>';
    _rightContent += ' <div class="localOperation">';
    _rightContent += '  <div class="chatSendContent">';
    _rightContent += '      <input type="button" class="chatClose" value="关闭" />';
    _rightContent += '     <input type="button" class="chatSend" value="发送" />';
    _rightContent += '  </div>';
    _rightContent += '  </div>';
    _rightContent += '  </div>';
    _rightContent += '   </div> ';

    $(".chatWindowsList").append(_rightContent);
    $(".chatTargetList ul li:last").trigger("click");
    $("#chatWindows").show();
    return _rightContent;
}
